define(['jquery'], function($) {

    var nodes = {};
    var slidePlayer = function(config) {
        var _that = this;
        var _config = config || {};

        _that.config = _config;


        _that.init.apply(_that);
    }

    slidePlayer.prototype = {
        init: function() {
            var _that = this;
            _that.collectNodes();
            _that.bindEvent();
        },

        render: function() {

        },

        collectNodes: function() {
            var _that = this;
            nodes.slidePlayer = $('#slidePlayer');
            nodes.fullScreen = $('#J-fullScreen');
            nodes.exitFullScreen = $('#J-exitFullScreen');
        },

        bindEvent: function() {
            var _that = this;


            _that.setFullScreen();
            _that.setUnFullScreen();
            _that.watchFullScreen();


        },

        nextFrame: function() {

        },

        prevFrame: function() {

        },

        setFullScreen() {
            var _that = this;
            nodes.fullScreen.on('click', function() {
                _that.fullScreen(nodes.slidePlayer);

            });
        },

        setUnFullScreen() {
            var _that = this;

            nodes.exitFullScreen.on('click', function() {
                _that.exitFullScreen.apply(nodes.slidePlayer);
            });

        },


        watchFullScreen: function() {
            var _that = this;

            $(document).on('fullscreenchange', function() {
                if (!_that.checkFullScreen()) {
                    nodes.fullScreen.show();
                    nodes.exitFullScreen.hide();
                } else {
                    nodes.fullScreen.hide();
                    nodes.exitFullScreen.show();
                }
            });



            $(document).on('mozfullscreenchange', function() {
                if (!_that.checkFullScreen()) {
                    nodes.fullScreen.show();
                    nodes.exitFullScreen.hide();
                } else {
                    nodes.fullScreen.hide();
                    nodes.exitFullScreen.show();
                }
            });

            $(document).on('webkitfullscreenchange', function() {
                if (!_that.checkFullScreen()) {
                    nodes.fullScreen.show();
                    nodes.exitFullScreen.hide();
                } else {
                    nodes.fullScreen.hide();
                    nodes.exitFullScreen.show();
                }
            });


            $(window).on('resize', function() {
                if (!_that.checkFullScreen()) {
                    nodes.fullScreen.show();
                    nodes.exitFullScreen.hide();
                } else {
                    nodes.fullScreen.hide();
                    nodes.exitFullScreen.show();
                }
            });
        },

        fullScreen: function(ele) {
            var _doc = document.documentElement;
            // 判断各种浏览器，找到正确的方法
            var requestMethod = _doc.requestFullScreen || //W3C
                _doc.webkitRequestFullScreen || //Chrome等
                _doc.mozRequestFullScreen || //FireFox
                _doc.msRequestFullScreen; //IE11

            if (requestMethod) {
                //借用[]的slice方法，将jQuery对象还原成dom对象伪数组，调用dom对象的原生方法
                requestMethod.call([].slice.apply(ele)[0]);
            } else if (typeof window.ActiveXObject !== 'undefined') {

                var wscript = new ActiveXObject('WScript.Shell');
                if (wscript !== null) {
                    wscript.SendKeys('{F11}');
                }
            }

        },

        exitFullScreen: function() {
            // 判断各种浏览器，找到正确的方法
            var exitMethod = document.exitFullscreen || //W3C
                document.mozCancelFullScreen || //Chrome等
                document.webkitExitFullscreen || //FireFox
                document.webkitExitFullscreen; //IE11

            if (exitMethod) {
                exitMethod.call(document);
            } else if (typeof window.ActiveXObject !== 'undefined') { //for Internet Explorer
                var wscript = new ActiveXObject('WScript.Shell');
                if (wscript !== null) {
                    wscript.SendKeys('{F11}');
                }
            }
        },

        checkFullScreen: function() {
            var isFull = document.fullscreenEnabled || window.fullScreen || document.webkitIsFullScreen || document.msFullscreenEnabled;
            //to fix : false || undefined == undefined
            if (isFull === undefined) {
                isFull = false;
            }
            return isFull;
        },


        shortCuts: function() {
            var _that = this;

        }

    }

    return slidePlayer;

});